﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Erp.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_MatlInv : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_InboundDetls_InboundRecs_InboundRecId",
                schema: "Erp",
                table: "InboundDetls");

            migrationBuilder.DropForeignKey(
                name: "FK_InboundDetls_MaterialInfos_MatlInfoId",
                schema: "Erp",
                table: "InboundDetls");

            migrationBuilder.DropForeignKey(
                name: "FK_InboundRecs_MaterialSuppliers_MatlSplerId",
                schema: "Erp",
                table: "InboundRecs");

            migrationBuilder.DropForeignKey(
                name: "FK_InboundRecs_MaterialWhses_MatlWhseId",
                schema: "Erp",
                table: "InboundRecs");

            migrationBuilder.DropForeignKey(
                name: "FK_MaterialAppyDetls_MaterialInfos_MaterialInfoID",
                schema: "Erp",
                table: "MaterialAppyDetls");

            migrationBuilder.DropForeignKey(
                name: "FK_MaterialWhses_MaterialWhses_MatlWhseId",
                schema: "Erp",
                table: "MaterialWhses");

            migrationBuilder.DropTable(
                name: "MaterialInventorys",
                schema: "Erp");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MaterialWhses",
                schema: "Erp",
                table: "MaterialWhses");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MaterialSuppliers",
                schema: "Erp",
                table: "MaterialSuppliers");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MaterialInfos",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.DropPrimaryKey(
                name: "PK_InboundRecs",
                schema: "Erp",
                table: "InboundRecs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_InboundDetls",
                schema: "Erp",
                table: "InboundDetls");

            migrationBuilder.RenameTable(
                name: "MaterialWhses",
                schema: "Erp",
                newName: "MatlWhse",
                newSchema: "Erp");

            migrationBuilder.RenameTable(
                name: "MaterialSuppliers",
                schema: "Erp",
                newName: "MatlSpler",
                newSchema: "Erp");

            migrationBuilder.RenameTable(
                name: "MaterialInfos",
                schema: "Erp",
                newName: "MatlInfo",
                newSchema: "Erp");

            migrationBuilder.RenameTable(
                name: "InboundRecs",
                schema: "Erp",
                newName: "InboundRec",
                newSchema: "Erp");

            migrationBuilder.RenameTable(
                name: "InboundDetls",
                schema: "Erp",
                newName: "InboundDetl",
                newSchema: "Erp");

            migrationBuilder.RenameIndex(
                name: "IX_MaterialWhses_MatlWhseId",
                schema: "Erp",
                table: "MatlWhse",
                newName: "IX_MatlWhse_MatlWhseId");

            migrationBuilder.RenameIndex(
                name: "IX_InboundRecs_MatlWhseId",
                schema: "Erp",
                table: "InboundRec",
                newName: "IX_InboundRec_MatlWhseId");

            migrationBuilder.RenameIndex(
                name: "IX_InboundRecs_MatlSplerId",
                schema: "Erp",
                table: "InboundRec",
                newName: "IX_InboundRec_MatlSplerId");

            migrationBuilder.RenameIndex(
                name: "IX_InboundDetls_MatlInfoId",
                schema: "Erp",
                table: "InboundDetl",
                newName: "IX_InboundDetl_MatlInfoId");

            migrationBuilder.RenameIndex(
                name: "IX_InboundDetls_InboundRecId",
                schema: "Erp",
                table: "InboundDetl",
                newName: "IX_InboundDetl_InboundRecId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MatlWhse",
                schema: "Erp",
                table: "MatlWhse",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MatlSpler",
                schema: "Erp",
                table: "MatlSpler",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MatlInfo",
                schema: "Erp",
                table: "MatlInfo",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_InboundRec",
                schema: "Erp",
                table: "InboundRec",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_InboundDetl",
                schema: "Erp",
                table: "InboundDetl",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "MatlInv",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MatlWhseId = table.Column<Guid>(type: "uuid", nullable: false),
                    MatlInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    TrdnFlag = table.Column<bool>(type: "boolean", nullable: false),
                    BatchNo = table.Column<string>(type: "text", nullable: false),
                    InvChgTypeCode = table.Column<string>(type: "text", nullable: false),
                    InvChgTypeName = table.Column<string>(type: "text", nullable: false),
                    OrdNo = table.Column<string>(type: "text", nullable: false),
                    ValiDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CurFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Ver = table.Column<long>(type: "bigint", nullable: false),
                    TotalCnt = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
                    OrderCnt = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
                    FinlCnt = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MatlInv", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MatlInv_MatlInfo_MatlInfoId",
                        column: x => x.MatlInfoId,
                        principalSchema: "Erp",
                        principalTable: "MatlInfo",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MatlInv_MatlWhse_MatlWhseId",
                        column: x => x.MatlWhseId,
                        principalSchema: "Erp",
                        principalTable: "MatlWhse",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MatlInv_MatlInfoId",
                schema: "Erp",
                table: "MatlInv",
                column: "MatlInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_MatlInv_MatlWhseId",
                schema: "Erp",
                table: "MatlInv",
                column: "MatlWhseId");

            migrationBuilder.AddForeignKey(
                name: "FK_InboundDetl_InboundRec_InboundRecId",
                schema: "Erp",
                table: "InboundDetl",
                column: "InboundRecId",
                principalSchema: "Erp",
                principalTable: "InboundRec",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_InboundDetl_MatlInfo_MatlInfoId",
                schema: "Erp",
                table: "InboundDetl",
                column: "MatlInfoId",
                principalSchema: "Erp",
                principalTable: "MatlInfo",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_InboundRec_MatlSpler_MatlSplerId",
                schema: "Erp",
                table: "InboundRec",
                column: "MatlSplerId",
                principalSchema: "Erp",
                principalTable: "MatlSpler",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_InboundRec_MatlWhse_MatlWhseId",
                schema: "Erp",
                table: "InboundRec",
                column: "MatlWhseId",
                principalSchema: "Erp",
                principalTable: "MatlWhse",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MaterialAppyDetls_MatlInfo_MaterialInfoID",
                schema: "Erp",
                table: "MaterialAppyDetls",
                column: "MaterialInfoID",
                principalSchema: "Erp",
                principalTable: "MatlInfo",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MatlWhse_MatlWhse_MatlWhseId",
                schema: "Erp",
                table: "MatlWhse",
                column: "MatlWhseId",
                principalSchema: "Erp",
                principalTable: "MatlWhse",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_InboundDetl_InboundRec_InboundRecId",
                schema: "Erp",
                table: "InboundDetl");

            migrationBuilder.DropForeignKey(
                name: "FK_InboundDetl_MatlInfo_MatlInfoId",
                schema: "Erp",
                table: "InboundDetl");

            migrationBuilder.DropForeignKey(
                name: "FK_InboundRec_MatlSpler_MatlSplerId",
                schema: "Erp",
                table: "InboundRec");

            migrationBuilder.DropForeignKey(
                name: "FK_InboundRec_MatlWhse_MatlWhseId",
                schema: "Erp",
                table: "InboundRec");

            migrationBuilder.DropForeignKey(
                name: "FK_MaterialAppyDetls_MatlInfo_MaterialInfoID",
                schema: "Erp",
                table: "MaterialAppyDetls");

            migrationBuilder.DropForeignKey(
                name: "FK_MatlWhse_MatlWhse_MatlWhseId",
                schema: "Erp",
                table: "MatlWhse");

            migrationBuilder.DropTable(
                name: "MatlInv",
                schema: "Erp");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MatlWhse",
                schema: "Erp",
                table: "MatlWhse");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MatlSpler",
                schema: "Erp",
                table: "MatlSpler");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MatlInfo",
                schema: "Erp",
                table: "MatlInfo");

            migrationBuilder.DropPrimaryKey(
                name: "PK_InboundRec",
                schema: "Erp",
                table: "InboundRec");

            migrationBuilder.DropPrimaryKey(
                name: "PK_InboundDetl",
                schema: "Erp",
                table: "InboundDetl");

            migrationBuilder.RenameTable(
                name: "MatlWhse",
                schema: "Erp",
                newName: "MaterialWhses",
                newSchema: "Erp");

            migrationBuilder.RenameTable(
                name: "MatlSpler",
                schema: "Erp",
                newName: "MaterialSuppliers",
                newSchema: "Erp");

            migrationBuilder.RenameTable(
                name: "MatlInfo",
                schema: "Erp",
                newName: "MaterialInfos",
                newSchema: "Erp");

            migrationBuilder.RenameTable(
                name: "InboundRec",
                schema: "Erp",
                newName: "InboundRecs",
                newSchema: "Erp");

            migrationBuilder.RenameTable(
                name: "InboundDetl",
                schema: "Erp",
                newName: "InboundDetls",
                newSchema: "Erp");

            migrationBuilder.RenameIndex(
                name: "IX_MatlWhse_MatlWhseId",
                schema: "Erp",
                table: "MaterialWhses",
                newName: "IX_MaterialWhses_MatlWhseId");

            migrationBuilder.RenameIndex(
                name: "IX_InboundRec_MatlWhseId",
                schema: "Erp",
                table: "InboundRecs",
                newName: "IX_InboundRecs_MatlWhseId");

            migrationBuilder.RenameIndex(
                name: "IX_InboundRec_MatlSplerId",
                schema: "Erp",
                table: "InboundRecs",
                newName: "IX_InboundRecs_MatlSplerId");

            migrationBuilder.RenameIndex(
                name: "IX_InboundDetl_MatlInfoId",
                schema: "Erp",
                table: "InboundDetls",
                newName: "IX_InboundDetls_MatlInfoId");

            migrationBuilder.RenameIndex(
                name: "IX_InboundDetl_InboundRecId",
                schema: "Erp",
                table: "InboundDetls",
                newName: "IX_InboundDetls_InboundRecId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MaterialWhses",
                schema: "Erp",
                table: "MaterialWhses",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MaterialSuppliers",
                schema: "Erp",
                table: "MaterialSuppliers",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MaterialInfos",
                schema: "Erp",
                table: "MaterialInfos",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_InboundRecs",
                schema: "Erp",
                table: "InboundRecs",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_InboundDetls",
                schema: "Erp",
                table: "InboundDetls",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "MaterialInventorys",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialWhseId = table.Column<Guid>(type: "uuid", nullable: false),
                    BatchNo = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    CurFlag = table.Column<bool>(type: "boolean", nullable: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    FinlCnt = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
                    InvType = table.Column<int>(type: "integer", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    OrderCnt = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
                    OrderNo = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    TotalCnt = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
                    TrdnFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ValidityDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    Ver = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MaterialInventorys", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MaterialInventorys_MaterialInfos_MaterialInfoId",
                        column: x => x.MaterialInfoId,
                        principalSchema: "Erp",
                        principalTable: "MaterialInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MaterialInventorys_MaterialWhses_MaterialWhseId",
                        column: x => x.MaterialWhseId,
                        principalSchema: "Erp",
                        principalTable: "MaterialWhses",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MaterialInventorys_MaterialInfoId",
                schema: "Erp",
                table: "MaterialInventorys",
                column: "MaterialInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_MaterialInventorys_MaterialWhseId",
                schema: "Erp",
                table: "MaterialInventorys",
                column: "MaterialWhseId");

            migrationBuilder.AddForeignKey(
                name: "FK_InboundDetls_InboundRecs_InboundRecId",
                schema: "Erp",
                table: "InboundDetls",
                column: "InboundRecId",
                principalSchema: "Erp",
                principalTable: "InboundRecs",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_InboundDetls_MaterialInfos_MatlInfoId",
                schema: "Erp",
                table: "InboundDetls",
                column: "MatlInfoId",
                principalSchema: "Erp",
                principalTable: "MaterialInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_InboundRecs_MaterialSuppliers_MatlSplerId",
                schema: "Erp",
                table: "InboundRecs",
                column: "MatlSplerId",
                principalSchema: "Erp",
                principalTable: "MaterialSuppliers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_InboundRecs_MaterialWhses_MatlWhseId",
                schema: "Erp",
                table: "InboundRecs",
                column: "MatlWhseId",
                principalSchema: "Erp",
                principalTable: "MaterialWhses",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MaterialAppyDetls_MaterialInfos_MaterialInfoID",
                schema: "Erp",
                table: "MaterialAppyDetls",
                column: "MaterialInfoID",
                principalSchema: "Erp",
                principalTable: "MaterialInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MaterialWhses_MaterialWhses_MatlWhseId",
                schema: "Erp",
                table: "MaterialWhses",
                column: "MatlWhseId",
                principalSchema: "Erp",
                principalTable: "MaterialWhses",
                principalColumn: "Id");
        }
    }
}
